package com.ruoyi.parkingcar.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.parkingcar.domain.ParkCustomer;
import com.ruoyi.parkingcar.service.IParkCustomerService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 普通客户信息Controller
 * 
 * @author 饼干
 * @date 2025-02-08
 */
@RestController
@RequestMapping("/parkingcar/customer")
public class ParkCustomerController extends BaseController {
    @Autowired
    private IParkCustomerService parkCustomerService;

    /**
     * 查询普通客户信息列表
     */
    @PreAuthorize("@ss.hasPermi('parkingcar:customer:list')")
    @GetMapping("/list")
    public TableDataInfo list(ParkCustomer parkCustomer) {
        startPage();
        List<ParkCustomer> list = parkCustomerService.selectParkCustomerList(parkCustomer);
        return getDataTable(list);
    }

    /**
     * 导出普通客户信息列表
     */
    @PreAuthorize("@ss.hasPermi('parkingcar:customer:export')")
    @Log(title = "普通客户信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ParkCustomer parkCustomer) {
        List<ParkCustomer> list = parkCustomerService.selectParkCustomerList(parkCustomer);
        ExcelUtil<ParkCustomer> util = new ExcelUtil<ParkCustomer>(ParkCustomer.class);
        util.exportExcel(response, list, "普通客户信息数据");
    }

    /**
     * 获取普通客户信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('parkingcar:customer:query')")
    @GetMapping(value = "/{customerId}")
    public AjaxResult getInfo(@PathVariable("customerId") Integer customerId) {
        return success(parkCustomerService.selectParkCustomerByCustomerId(customerId));
    }

    /**
     * 新增普通客户信息
     */
    @PreAuthorize("@ss.hasPermi('parkingcar:customer:add')")
    @Log(title = "普通客户信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ParkCustomer parkCustomer) {
        return toAjax(parkCustomerService.insertParkCustomer(parkCustomer));
    }

    /**
     * 修改普通客户信息
     */
    @PreAuthorize("@ss.hasPermi('parkingcar:customer:edit')")
    @Log(title = "普通客户信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ParkCustomer parkCustomer) {
        return toAjax(parkCustomerService.updateParkCustomer(parkCustomer));
    }

    /**
     * 删除普通客户信息
     */
    @PreAuthorize("@ss.hasPermi('parkingcar:customer:remove')")
    @Log(title = "普通客户信息", businessType = BusinessType.DELETE)
    @DeleteMapping("/{customerIds}")
    public AjaxResult remove(@PathVariable Integer[] customerIds) {
        return toAjax(parkCustomerService.deleteParkCustomerByCustomerIds(customerIds));
    }


    //登录
    @RequestMapping("/login")
    public AjaxResult login(@RequestBody ParkCustomer parkCustomer) {

        ParkCustomer login = parkCustomerService.login(parkCustomer.getCustomerAcc(), parkCustomer.getCustomerPwd());

        if (login == null) {
            return AjaxResult.error("登陆失败");
        }
        return AjaxResult.success("登录成功").put("parkCustomer", login);
    }

    //注册
    @RequestMapping("/register")
    public AjaxResult register(@RequestBody ParkCustomer parkCustomer) {
        int result = parkCustomerService.register(parkCustomer);
        if (result > 0  ) {
            return AjaxResult.success("注册成功").put("parkCustomer", parkCustomer);
        }
        return AjaxResult.error("注册失败");
    }



}